package top.lingkang.finaloauth.server.config;

import org.springframework.beans.factory.annotation.Autowired;
import top.lingkang.finaloauth.entity.OauthClient;
import top.lingkang.finaloauth.entity.OauthUser;
import top.lingkang.finaloauth.server.base.ClientRepository;
import top.lingkang.finaloauth.server.base.GenerateToken;
import top.lingkang.finaloauth.server.base.OauthUserRepository;

import java.util.List;

/**
 * @author lingkang
 * Created by 2022/3/16
 */
public class OauthServerConfigurationAdapter {
    private OauthServerConfig config = new OauthServerConfig();

    @Autowired
    private ClientRepository clientRepository;
    @Autowired
    private OauthUserRepository oauthUserRepository;
    @Autowired
    private GenerateToken generateToken;

    public OauthServerConfigurationAdapter() {
        configure(config);

        // 添加默认
        if (config.getOauthClients().isEmpty()) {
            OauthClient client = new OauthClient();
            client.setClientId("client_id");
            client.setClientSecret("client_secret");
            String[] type = new String[]{"password", "code", "token"};
            client.setGrantType(type);
            clientRepository.add(client);
        } else {
            for (OauthClient client : config.getOauthClients()) {
                clientRepository.add(client);
            }
        }
        List<OauthUser> oauthUsers = config.getOauthUsers();





    }

    protected void configure(OauthServerConfig config) {

    }
}
